<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Db_Adapter - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.db.adapter.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.db.adapter.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.db.html">Zend_Db</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.db.html">Zend_Db</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.db.statement.html">Zend_Db_Statement</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.db.adapter" class="section"><div class="info"><h1 class="title">Zend_Db_Adapter</h1></div>
    

    <p class="para">
        <span class="classname">Zend_Db</span> and its related classes provide a simple
        <acronym class="acronym">SQL</acronym> database interface for Zend Framework. The
        <span class="classname">Zend_Db_Adapter</span> is the basic class you use to connect your
        <acronym class="acronym">PHP</acronym> application to an <acronym class="acronym">RDBMS</acronym>. There is a different
        Adapter class for each brand of <acronym class="acronym">RDBMS</acronym>.
    </p>

    <p class="para">
        The <span class="classname">Zend_Db</span> adapters create a bridge from the vendor-specific
        <acronym class="acronym">PHP</acronym> extensions to a common interface to help you write
        <acronym class="acronym">PHP</acronym> applications once and deploy with multiple brands of
        <acronym class="acronym">RDBMS</acronym> with very little effort.
    </p>

    <p class="para">
        The interface of the adapter class is similar to the interface of the
        <a href="http://www.php.net/pdo" class="link external">&raquo; PHP Data Objects</a> extension.
        <span class="classname">Zend_Db</span> provides Adapter classes to <acronym class="acronym">PDO</acronym> drivers
        for the following <acronym class="acronym">RDBMS</acronym> brands:
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para">
                <acronym class="acronym">IBM</acronym> <acronym class="acronym">DB2</acronym> and Informix Dynamic Server
                (<acronym class="acronym">IDS</acronym>), using the <a href="http://www.php.net/pdo-ibm" class="link external">&raquo; pdo_ibm</a> <acronym class="acronym">PHP</acronym>
                extension
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                MariaDB, using the <a href="http://www.php.net/pdo-mysql" class="link external">&raquo; pdo_mysql</a>
                <acronym class="acronym">PHP</acronym> extension
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                MySQL, using the <a href="http://www.php.net/pdo-mysql" class="link external">&raquo; pdo_mysql</a>
                <acronym class="acronym">PHP</acronym> extension
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                Microsoft <acronym class="acronym">SQL</acronym> Server, using the <a href="http://www.php.net/pdo-dblib" class="link external">&raquo; pdo_dblib</a> <acronym class="acronym">PHP</acronym>
                extension
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                Oracle, using the <a href="http://www.php.net/pdo-oci" class="link external">&raquo; pdo_oci</a>
                <acronym class="acronym">PHP</acronym> extension
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                PostgreSQL, using the <a href="http://www.php.net/pdo-pgsql" class="link external">&raquo; pdo_pgsql</a>
                <acronym class="acronym">PHP</acronym> extension
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                SQLite, using the <a href="http://www.php.net/pdo-sqlite" class="link external">&raquo; pdo_sqlite</a>
                <acronym class="acronym">PHP</acronym> extension
            </p>
        </li>
    </ul>

    <p class="para">
        In addition, <span class="classname">Zend_Db</span> provides Adapter classes that utilize
        <acronym class="acronym">PHP</acronym> database extensions for the following <acronym class="acronym">RDBMS</acronym>
        brands:
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para">
                MariaDB, using the <a href="http://www.php.net/mysqli" class="link external">&raquo; mysqli</a>
                <acronym class="acronym">PHP</acronym> extension
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                MySQL, using the <a href="http://www.php.net/mysqli" class="link external">&raquo; mysqli</a>
                <acronym class="acronym">PHP</acronym> extension
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                Oracle, using the <a href="http://www.php.net/oci8" class="link external">&raquo; oci8</a>
                <acronym class="acronym">PHP</acronym> extension
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <acronym class="acronym">IBM</acronym> <acronym class="acronym">DB2</acronym> and <acronym class="acronym">DB2</acronym> I5, using
                the <a href="http://www.php.net/ibm_db2" class="link external">&raquo; ibm_db2</a> <acronym class="acronym">PHP</acronym>
                extension
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                Firebird (Interbase), using the <a href="http://www.php.net/ibase" class="link external">&raquo; php_interbase</a> <acronym class="acronym">PHP</acronym>
                extension
            </p>
        </li>
    </ul>

    <blockquote class="note"><p><b class="note">Note</b>: 
        <p class="para">
            Each <span class="classname">Zend_Db</span> Adapter uses a <acronym class="acronym">PHP</acronym> extension. You
            must have the respective <acronym class="acronym">PHP</acronym> extension enabled in your
            <acronym class="acronym">PHP</acronym> environment to use a <span class="classname">Zend_Db</span> Adapter. For
            example, if you use any of the <acronym class="acronym">PDO</acronym> <span class="classname">Zend_Db</span>
            Adapters, you need to enable both the <acronym class="acronym">PDO</acronym> extension and the
            <acronym class="acronym">PDO</acronym> driver for the brand of <acronym class="acronym">RDBMS</acronym> you use.
        </p>
    </p></blockquote>

    <div class="section" id="zend.db.adapter.connecting"><div class="info"><h1 class="title">Connecting to a Database Using an Adapter</h1></div>
        

        <p class="para">
            This section describes how to create an instance of a database Adapter.
            This corresponds to making a connection to your <acronym class="acronym">RDBMS</acronym> server from
            your <acronym class="acronym">PHP</acronym> application.
        </p>

        <div class="section" id="zend.db.adapter.connecting.constructor"><div class="info"><h1 class="title">Using a Zend_Db Adapter Constructor</h1></div>
            

            <p class="para">
                You can create an instance of an adapter using its constructor.
                An adapter constructor takes one argument, which is an array
                of parameters used to declare the connection.
            </p>

            <div class="example" id="zend.db.adapter.connecting.constructor.example"><div class="info"><p><b>Example #1 Using an Adapter Constructor</b></p></div>
                

                <pre class="programlisting brush: php">
$db = new Zend_Db_Adapter_Pdo_Mysql(array(
    &#039;host&#039;     =&gt; &#039;127.0.0.1&#039;,
    &#039;username&#039; =&gt; &#039;webuser&#039;,
    &#039;password&#039; =&gt; &#039;xxxxxxxx&#039;,
    &#039;dbname&#039;   =&gt; &#039;test&#039;
));
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.connecting.factory"><div class="info"><h1 class="title">Using the Zend_Db Factory</h1></div>
            

            <p class="para">
                As an alternative to using an adapter constructor directly, you
                can create an instance of an adapter using the static method
                 <span class="methodname">Zend_Db::factory()</span>. This method dynamically loads
                the adapter class file on demand using
                <a href="zend.loader.load.html#zend.loader.load.class" class="link">Zend_Loader::loadClass()</a>.
            </p>

            <p class="para">
                The first argument is a string that names the base name of the
                adapter class. For example the string &#039;<span class="classname">Pdo_Mysql</span>&#039; corresponds
                to the class <span class="classname">Zend_Db_Adapter_Pdo_Mysql</span>. The second argument
                is the same array of parameters you would have given to the
                adapter constructor.
            </p>

            <div class="example" id="zend.db.adapter.connecting.factory.example"><div class="info"><p><b>Example #2 Using the Adapter Factory Method</b></p></div>
                

                <pre class="programlisting brush: php">
// We don&#039;t need the following statement because the
// Zend_Db_Adapter_Pdo_Mysql file will be loaded for us by the Zend_Db
// factory method.

// require_once &#039;Zend/Db/Adapter/Pdo/Mysql.php&#039;;

// Automatically load class Zend_Db_Adapter_Pdo_Mysql
// and create an instance of it.
$db = Zend_Db::factory(&#039;Pdo_Mysql&#039;, array(
    &#039;host&#039;     =&gt; &#039;127.0.0.1&#039;,
    &#039;username&#039; =&gt; &#039;webuser&#039;,
    &#039;password&#039; =&gt; &#039;xxxxxxxx&#039;,
    &#039;dbname&#039;   =&gt; &#039;test&#039;
));
</pre>

            </div>

            <p class="para">
                If you create your own class that extends
                <span class="classname">Zend_Db_Adapter_Abstract</span>, but you do not name your
                class with the &quot;<span class="classname">Zend_Db_Adapter</span>&quot; package prefix, you can use
                the  <span class="methodname">factory()</span> method to load your adapter if you
                specify the leading portion of the adapter class with the
                &#039;adapterNamespace&#039; key in the parameters array.
            </p>

            <div class="example" id="zend.db.adapter.connecting.factory.example2"><div class="info"><p><b>Example #3 Using the Adapter Factory Method for a Custom Adapter Class</b></p></div>
                

                <pre class="programlisting brush: php">
// We don&#039;t need to load the adapter class file
// because it will be loaded for us by the Zend_Db factory method.

// Automatically load class MyProject_Db_Adapter_Pdo_Mysql and create
// an instance of it.
$db = Zend_Db::factory(&#039;Pdo_Mysql&#039;, array(
    &#039;host&#039;             =&gt; &#039;127.0.0.1&#039;,
    &#039;username&#039;         =&gt; &#039;webuser&#039;,
    &#039;password&#039;         =&gt; &#039;xxxxxxxx&#039;,
    &#039;dbname&#039;           =&gt; &#039;test&#039;,
    &#039;adapterNamespace&#039; =&gt; &#039;MyProject_Db_Adapter&#039;
));
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.connecting.factory-config"><div class="info"><h1 class="title">Using Zend_Config with the Zend_Db Factory</h1></div>
            

            <p class="para">
                Optionally, you may specify either argument of the
                 <span class="methodname">factory()</span> method as an object of type
                <a href="zend.config.html" class="link">Zend_Config</a>.
            </p>

            <p class="para">
                If the first argument is a config object, it is expected to
                contain a property named <span class="property">adapter</span>, containing the
                string naming the adapter class name base. Optionally, the object
                may contain a property named <span class="property">params</span>, with
                subproperties corresponding to adapter parameter names.
                This is used only if the second argument of the
                 <span class="methodname">factory()</span> method is absent.
            </p>

            <div class="example" id="zend.db.adapter.connecting.factory.example1"><div class="info"><p><b>Example #4 Using the Adapter Factory Method with a Zend_Config Object</b></p></div>
                

                <div class="example-contents"><p>
                    In the example below, a <span class="classname">Zend_Config</span> object is created
                    from an array. You can also load data from an external file using classes such
                    as <a href="zend.config.adapters.ini.html" class="link">Zend_Config_Ini</a>
                    and <a href="zend.config.adapters.xml.html" class="link">Zend_Config_Xml</a>.
                </p></div>

                <pre class="programlisting brush: php">
$config = new Zend_Config(
    array(
        &#039;database&#039; =&gt; array(
            &#039;adapter&#039; =&gt; &#039;Mysqli&#039;,
            &#039;params&#039;  =&gt; array(
                &#039;host&#039;     =&gt; &#039;127.0.0.1&#039;,
                &#039;dbname&#039;   =&gt; &#039;test&#039;,
                &#039;username&#039; =&gt; &#039;webuser&#039;,
                &#039;password&#039; =&gt; &#039;secret&#039;,
            )
        )
    )
);

$db = Zend_Db::factory($config-&gt;database);
</pre>

            </div>

            <p class="para">
                The second argument of the  <span class="methodname">factory()</span> method may be
                an associative array containing entries corresponding to
                adapter parameters. This argument is optional. If the first
                argument is of type <span class="classname">Zend_Config</span>, it is assumed to contain all
                parameters, and the second argument is ignored.
            </p>
        </div>

        <div class="section" id="zend.db.adapter.connecting.parameters"><div class="info"><h1 class="title">Adapter Parameters</h1></div>
            

            <p class="para">
                The following list explains common parameters recognized by
                <span class="classname">Zend_Db</span> Adapter classes.
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">host</em>:
                        a string containing a hostname or IP address of the
                        database server. If the database is running on the
                        same host as the <acronym class="acronym">PHP</acronym> application, you may use
                        &#039;localhost&#039; or &#039;127.0.0.1&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">username</em>:
                        account identifier for authenticating a connection to the
                        <acronym class="acronym">RDBMS</acronym> server.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">password</em>:
                        account password credential for authenticating a
                        connection to the <acronym class="acronym">RDBMS</acronym> server.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">dbname</em>:
                        database instance name on the <acronym class="acronym">RDBMS</acronym> server.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">port</em>:
                        some <acronym class="acronym">RDBMS</acronym> servers can accept network connections on a
                        administrator-specified port number. The port
                        parameter allow you to specify the port to which your
                        <acronym class="acronym">PHP</acronym> application connects, to match the port configured
                        on the <acronym class="acronym">RDBMS</acronym> server.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">charset</em>:
                        specify the charset used for the connection.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">options</em>:
                        this parameter is an associative array of options
                        that are generic to all <span class="classname">Zend_Db_Adapter</span> classes.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">driver_options</em>:
                        this parameter is an associative array of additional
                        options that are specific to a given database
                        extension. One typical use of this parameter is to
                        set attributes of a <acronym class="acronym">PDO</acronym> driver.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis">adapterNamespace</em>:
                        names the initial part of the class name for the
                        adapter, instead of &#039;<span class="classname">Zend_Db_Adapter</span>&#039;. Use this if
                        you need to use the  <span class="methodname">factory()</span> method to
                        load a non-Zend database adapter class.
                    </p>
                </li>
            </ul>

            <div class="example" id="zend.db.adapter.connecting.parameters.example1"><div class="info"><p><b>Example #5 Passing the Case-Folding Option to the Factory</b></p></div>
                

                <div class="example-contents"><p>
                    You can specify this option by the constant
                    <b><tt>Zend_Db::CASE_FOLDING</tt></b>.
                    This corresponds to the <b><tt>ATTR_CASE</tt></b> attribute in
                    <acronym class="acronym">PDO</acronym> and <acronym class="acronym">IBM</acronym> <acronym class="acronym">DB2</acronym>
                    database drivers, adjusting the case of string keys in query result sets. The
                    option takes values <b><tt>Zend_Db::CASE_NATURAL</tt></b> (the default),
                    <b><tt>Zend_Db::CASE_UPPER</tt></b>, and
                    <b><tt>Zend_Db::CASE_LOWER</tt></b>.
                </p></div>

                <pre class="programlisting brush: php">
$options = array(
    Zend_Db::CASE_FOLDING =&gt; Zend_Db::CASE_UPPER
);

$params = array(
    &#039;host&#039;           =&gt; &#039;127.0.0.1&#039;,
    &#039;username&#039;       =&gt; &#039;webuser&#039;,
    &#039;password&#039;       =&gt; &#039;xxxxxxxx&#039;,
    &#039;dbname&#039;         =&gt; &#039;test&#039;,
    &#039;options&#039;        =&gt; $options
);

$db = Zend_Db::factory(&#039;Db2&#039;, $params);
</pre>

            </div>

            <div class="example" id="zend.db.adapter.connecting.parameters.example2"><div class="info"><p><b>Example #6 Passing the Auto-Quoting Option to the Factory</b></p></div>
                

                <div class="example-contents"><p>
                    You can specify this option by the constant
                    <b><tt>Zend_Db::AUTO_QUOTE_IDENTIFIERS</tt></b>. If the value
                    is <b><tt>TRUE</tt></b> (the default), identifiers like table
                    names, column names, and even aliases are delimited in all
                    <acronym class="acronym">SQL</acronym> syntax generated by the Adapter object. This makes it
                    simple to use identifiers that contain <acronym class="acronym">SQL</acronym> keywords, or
                    special characters. If the value is <b><tt>FALSE</tt></b>,
                    identifiers are not delimited automatically. If you need
                    to delimit identifiers, you must do so yourself using the
                     <span class="methodname">quoteIdentifier()</span> method.
                </p></div>

                <pre class="programlisting brush: php">
$options = array(
    Zend_Db::AUTO_QUOTE_IDENTIFIERS =&gt; false
);

$params = array(
    &#039;host&#039;           =&gt; &#039;127.0.0.1&#039;,
    &#039;username&#039;       =&gt; &#039;webuser&#039;,
    &#039;password&#039;       =&gt; &#039;xxxxxxxx&#039;,
    &#039;dbname&#039;         =&gt; &#039;test&#039;,
    &#039;options&#039;        =&gt; $options
);

$db = Zend_Db::factory(&#039;Pdo_Mysql&#039;, $params);
</pre>

            </div>

            <div class="example" id="zend.db.adapter.connecting.parameters.example3"><div class="info"><p><b>Example #7 Passing PDO Driver Options to the Factory</b></p></div>
                

                <pre class="programlisting brush: php">
$pdoParams = array(
    PDO::MYSQL_ATTR_USE_BUFFERED_QUERY =&gt; true
);

$params = array(
    &#039;host&#039;           =&gt; &#039;127.0.0.1&#039;,
    &#039;username&#039;       =&gt; &#039;webuser&#039;,
    &#039;password&#039;       =&gt; &#039;xxxxxxxx&#039;,
    &#039;dbname&#039;         =&gt; &#039;test&#039;,
    &#039;driver_options&#039; =&gt; $pdoParams
);

$db = Zend_Db::factory(&#039;Pdo_Mysql&#039;, $params);

echo $db-&gt;getConnection()
        -&gt;getAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY);
</pre>

            </div>

            <div class="example" id="zend.db.adapter.connecting.parameters.example4"><div class="info"><p><b>Example #8 Passing Serialization Options to the Factory</b></p></div>
                

                <pre class="programlisting brush: php">
$options = array(
    Zend_Db::ALLOW_SERIALIZATION =&gt; false
);

$params = array(
    &#039;host&#039;           =&gt; &#039;127.0.0.1&#039;,
    &#039;username&#039;       =&gt; &#039;webuser&#039;,
    &#039;password&#039;       =&gt; &#039;xxxxxxxx&#039;,
    &#039;dbname&#039;         =&gt; &#039;test&#039;,
    &#039;options&#039;        =&gt; $options
);

$db = Zend_Db::factory(&#039;Pdo_Mysql&#039;, $params);
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.connecting.getconnection"><div class="info"><h1 class="title">Managing Lazy Connections</h1></div>
            

            <p class="para">
                Creating an instance of an Adapter class does not immediately
                connect to the <acronym class="acronym">RDBMS</acronym> server. The Adapter saves the connection
                parameters, and makes the actual connection on demand, the
                first time you need to execute a query. This ensures that
                creating an Adapter object is quick and inexpensive. You can
                create an instance of an Adapter even if you are not certain
                that you need to run any database queries during the current
                request your application is serving.
            </p>

            <p class="para">
                If you need to force the Adapter to connect to the <acronym class="acronym">RDBMS</acronym>, use
                the  <span class="methodname">getConnection()</span> method. This method returns
                an object for the connection as represented by the respective
                <acronym class="acronym">PHP</acronym> database extension. For example, if you use any of the
                Adapter classes for <acronym class="acronym">PDO</acronym> drivers, then
                 <span class="methodname">getConnection()</span> returns the <acronym class="acronym">PDO</acronym> object,
                after initiating it as a live connection to the specific database.
            </p>

            <p class="para">
                It can be useful to force the connection if you want to catch
                any exceptions it throws as a result of invalid account
                credentials, or other failure to connect to the <acronym class="acronym">RDBMS</acronym> server.
                These exceptions are not thrown until the connection is made,
                so it can help simplify your application code if you handle the
                exceptions in one place, instead of at the time of
                the first query against the database.
            </p>

            <p class="para">
                Additionally, an adapter can get serialized to store it, for example,
                in a session variable. This can be very useful not only for the
                adapter itself, but for other objects that aggregate it, like a
                <span class="classname">Zend_Db_Select</span> object. By default, adapters are allowed
                to be serialized, if you don&#039;t want it, you should consider passing the
                <b><tt>Zend_Db::ALLOW_SERIALIZATION</tt></b> option with
                <b><tt>FALSE</tt></b>, see the example above. To respect lazy connections
                principle, the adapter won&#039;t reconnect itself after being unserialized. You must
                then call  <span class="methodname">getConnection()</span> yourself. You can make the
                adapter auto-reconnect by passing the
                <b><tt>Zend_Db::AUTO_RECONNECT_ON_UNSERIALIZE</tt></b> with
                <b><tt>TRUE</tt></b> as an adapter option.
            </p>

            <div class="example" id="zend.db.adapter.connecting.getconnection.example"><div class="info"><p><b>Example #9 Handling Connection Exceptions</b></p></div>
                

                <pre class="programlisting brush: php">
try {
    $db = Zend_Db::factory(&#039;Pdo_Mysql&#039;, $parameters);
    $db-&gt;getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
    // perhaps a failed login credential, or perhaps the RDBMS is not running
} catch (Zend_Exception $e) {
    // perhaps factory() failed to load the specified Adapter class
}
</pre>

            </div>
        </div>
    </div>

    <div class="section" id="zend.db.adapter.example-database"><div class="info"><h1 class="title">Example Database</h1></div>
        

        <p class="para">
            In the documentation for <span class="classname">Zend_Db</span> classes, we use a set of simple
            tables to illustrate usage of the classes and methods. These
            example tables could store information for tracking bugs in a
            software development project. The database contains four tables:
        </p>

        <ul class="itemizedlist">
            <li class="listitem">
                <p class="para">
                    <em class="emphasis">accounts</em> stores
                    information about each user of the bug-tracking database.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">products</em> stores
                    information about each product for which a bug can be
                    logged.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">bugs</em> stores information
                    about bugs, including that current state of the bug, the
                    person who reported the bug, the person who is assigned to
                    fix the bug, and the person who is assigned to verify the
                    fix.
                </p>
            </li>

            <li class="listitem">
                <p class="para">
                    <em class="emphasis">bugs_products</em> stores a
                    relationship between bugs and products. This implements a
                    many-to-many relationship, because a given bug may be
                    relevant to multiple products, and of course a given
                    product can have multiple bugs.
                </p>
            </li>
        </ul>

        <p class="para">
            The following <acronym class="acronym">SQL</acronym> data definition language pseudocode describes the
            tables in this example database. These example tables are used
            extensively by the automated unit tests for <span class="classname">Zend_Db</span>.
        </p>

        <pre class="programlisting brush: sql">
CREATE TABLE accounts (
  account_name      VARCHAR(100) NOT NULL PRIMARY KEY
);

CREATE TABLE products (
  product_id        INTEGER NOT NULL PRIMARY KEY,
  product_name      VARCHAR(100)
);

CREATE TABLE bugs (
  bug_id            INTEGER NOT NULL PRIMARY KEY,
  bug_description   VARCHAR(100),
  bug_status        VARCHAR(20),
  reported_by       VARCHAR(100) REFERENCES accounts(account_name),
  assigned_to       VARCHAR(100) REFERENCES accounts(account_name),
  verified_by       VARCHAR(100) REFERENCES accounts(account_name)
);

CREATE TABLE bugs_products (
  bug_id            INTEGER NOT NULL REFERENCES bugs,
  product_id        INTEGER NOT NULL REFERENCES products,
  PRIMARY KEY       (bug_id, product_id)
);
</pre>


        <p class="para">
            Also notice that the &#039;bugs&#039; table contains multiple
            foreign key references to the &#039;accounts&#039; table.
            Each of these foreign keys may reference a different row in the
            &#039;accounts&#039; table for a given bug.
        </p>

        <p class="para">
            The diagram below illustrates the physical data model of the
            example database.
        </p>

        <p class="para">
            <div class="inlinemediaobject"><div class="imageobject"><img src="images/d481d625821a97b9a5eb2cec99dca50e-zend.db.adapter.example-database.png" alt="zend.db.adapter.example-database.png" width="387" height="302" /></div></div>
        </p>
    </div>

    <div class="section" id="zend.db.adapter.select"><div class="info"><h1 class="title">Reading Query Results</h1></div>
        

        <p class="para">
            This section describes methods of the Adapter class with which you
            can run <acronym class="acronym">SELECT</acronym> queries and retrieve the query results.
        </p>

        <div class="section" id="zend.db.adapter.select.fetchall"><div class="info"><h1 class="title">Fetching a Complete Result Set</h1></div>
            

            <p class="para">
                You can run a <acronym class="acronym">SQL</acronym> <acronym class="acronym">SELECT</acronym> query and retrieve
                its results in one step using the  <span class="methodname">fetchAll()</span> method.
            </p>

            <p class="para">
                The first argument to this method is a string containing a
                <acronym class="acronym">SELECT</acronym> statement. Alternatively, the first argument can be an
                object of class <a href="zend.db.select.html" class="link">Zend_Db_Select</a>.
                The Adapter automatically converts this object to a string
                representation of the <acronym class="acronym">SELECT</acronym> statement.
            </p>

            <p class="para">
                The second argument to  <span class="methodname">fetchAll()</span> is an array of
                values to substitute for parameter placeholders in the <acronym class="acronym">SQL</acronym>
                statement.
            </p>

            <div class="example" id="zend.db.adapter.select.fetchall.example"><div class="info"><p><b>Example #10 Using fetchAll()</b></p></div>
                

                <pre class="programlisting brush: php">
$sql = &#039;SELECT * FROM bugs WHERE bug_id = ?&#039;;

$result = $db-&gt;fetchAll($sql, 2);
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.select.fetch-mode"><div class="info"><h1 class="title">Changing the Fetch Mode</h1></div>
            

            <p class="para">
                By default,  <span class="methodname">fetchAll()</span> returns an array of
                rows, each of which is an associative array. The keys of the
                associative array are the columns or column aliases named in
                the select query.
            </p>

            <p class="para">
                You can specify a different style of fetching results using the
                 <span class="methodname">setFetchMode()</span> method. The modes supported are
                identified by constants:
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        <em class="emphasis"><b><tt>Zend_Db::FETCH_ASSOC</tt></b></em>:
                        return data in an array of associative arrays.
                        The array keys are column names, as strings. This is the default fetch mode
                        for <span class="classname">Zend_Db_Adapter</span> classes.
                    </p>

                    <p class="para">
                        Note that if your select-list contains more than one
                        column with the same name, for example if they are from
                        two different tables in a <acronym class="acronym">JOIN</acronym>, there can be only one
                        entry in the associative array for a given name.
                        If you use the <b><tt>FETCH_ASSOC</tt></b> mode, you should specify
                        column aliases in your <acronym class="acronym">SELECT</acronym> query to ensure that the
                        names result in unique array keys.
                    </p>

                    <p class="para">
                        By default, these strings are returned as they are
                        returned by the database driver. This is typically the
                        spelling of the column in the <acronym class="acronym">RDBMS</acronym> server. You can
                        specify the case for these strings, using the
                        <b><tt>Zend_Db::CASE_FOLDING</tt></b> option.
                        Specify this when instantiating the Adapter.
                        See <a href="zend.db.adapter.html#zend.db.adapter.connecting.parameters.example1" class="link">this
                            example</a>
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis"><b><tt>Zend_Db::FETCH_NUM</tt></b></em>:
                        return data in an array of arrays. The arrays are
                        indexed by integers, corresponding to the position of
                        the respective field in the select-list of the query.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis"><b><tt>Zend_Db::FETCH_BOTH</tt></b></em>:
                        return data in an array of arrays. The array keys are
                        both strings as used in the <b><tt>FETCH_ASSOC</tt></b> mode, and
                        integers as used in the <b><tt>FETCH_NUM</tt></b> mode. Note that the
                        number of elements in the array is double that which
                        would be in the array if you used either <b><tt>FETCH_ASSOC</tt></b>
                        or <b><tt>FETCH_NUM</tt></b>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis"><b><tt>Zend_Db::FETCH_COLUMN</tt></b></em>:
                        return data in an array of values. The value in each array
                        is the value returned by one column of the result set.
                        By default, this is the first column, indexed by 0.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <em class="emphasis"><b><tt>Zend_Db::FETCH_OBJ</tt></b></em>:
                        return data in an array of objects. The default class
                        is the <acronym class="acronym">PHP</acronym> built-in class stdClass. Columns of the
                        result set are available as public properties of the
                        object.
                    </p>
                </li>
            </ul>

            <div class="example" id="zend.db.adapter.select.fetch-mode.example"><div class="info"><p><b>Example #11 Using setFetchMode()</b></p></div>
                

                <pre class="programlisting brush: php">
$db-&gt;setFetchMode(Zend_Db::FETCH_OBJ);

$result = $db-&gt;fetchAll(&#039;SELECT * FROM bugs WHERE bug_id = ?&#039;, 2);

// $result is an array of objects
echo $result[0]-&gt;bug_description;
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.select.fetchassoc"><div class="info"><h1 class="title">Fetching a Result Set as an Associative Array</h1></div>
            

            <p class="para">
                The  <span class="methodname">fetchAssoc()</span> method returns data in an array
                of associative arrays, regardless of what value you have set
                for the fetch mode, using the first column as the array index.
            </p>

            <div class="example" id="zend.db.adapter.select.fetchassoc.example"><div class="info"><p><b>Example #12 Using fetchAssoc()</b></p></div>
                

                <pre class="programlisting brush: php">
$db-&gt;setFetchMode(Zend_Db::FETCH_OBJ);

$result = $db-&gt;fetchAssoc(
    &#039;SELECT bug_id, bug_description, bug_status FROM bugs&#039;
);

// $result is an array of associative arrays, in spite of the fetch mode
echo $result[2][&#039;bug_description&#039;]; // Description of Bug #2
echo $result[1][&#039;bug_description&#039;]; // Description of Bug #1
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.select.fetchcol"><div class="info"><h1 class="title">Fetching a Single Column from a Result Set</h1></div>
            

            <p class="para">
                The  <span class="methodname">fetchCol()</span> method returns data in an array
                of values, regardless of the value you have set for the fetch mode.
                This only returns the first column returned by the query.
                Any other columns returned by the query are discarded.
                If you need to return a column other than the first, see
                <a href="zend.db.statement.html#zend.db.statement.fetching.fetchcolumn" class="link">this section</a>.
            </p>

            <div class="example" id="zend.db.adapter.select.fetchcol.example"><div class="info"><p><b>Example #13 Using fetchCol()</b></p></div>
                

                <pre class="programlisting brush: php">
$db-&gt;setFetchMode(Zend_Db::FETCH_OBJ);

$result = $db-&gt;fetchCol(
    &#039;SELECT bug_description, bug_id FROM bugs WHERE bug_id = ?&#039;, 2);

// contains bug_description; bug_id is not returned
echo $result[0];
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.select.fetchpairs"><div class="info"><h1 class="title">Fetching Key-Value Pairs from a Result Set</h1></div>
            

            <p class="para">
                The  <span class="methodname">fetchPairs()</span> method returns data in an array
                of key-value pairs, as an associative array with a single entry
                per row. The key of this associative array is taken from the
                first column returned by the <acronym class="acronym">SELECT</acronym> query. The value is taken
                from the second column returned by the <acronym class="acronym">SELECT</acronym> query. Any other
                columns returned by the query are discarded.
            </p>

            <p class="para">
                You should design the <acronym class="acronym">SELECT</acronym> query so that the first column
                returned has unique values. If there are duplicates values in
                the first column, entries in the associative array will be
                overwritten.
            </p>

            <div class="example" id="zend.db.adapter.select.fetchpairs.example"><div class="info"><p><b>Example #14 Using fetchPairs()</b></p></div>
                

                <pre class="programlisting brush: php">
$db-&gt;setFetchMode(Zend_Db::FETCH_OBJ);

$result = $db-&gt;fetchPairs(&#039;SELECT bug_id, bug_status FROM bugs&#039;);

echo $result[2];
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.select.fetchrow"><div class="info"><h1 class="title">Fetching a Single Row from a Result Set</h1></div>
            

            <p class="para">
                The  <span class="methodname">fetchRow()</span> method returns data using the
                current fetch mode, but it returns only the first row
                fetched from the result set.
            </p>

            <div class="example" id="zend.db.adapter.select.fetchrow.example"><div class="info"><p><b>Example #15 Using fetchRow()</b></p></div>
                

                <pre class="programlisting brush: php">
$db-&gt;setFetchMode(Zend_Db::FETCH_OBJ);

$result = $db-&gt;fetchRow(&#039;SELECT * FROM bugs WHERE bug_id = 2&#039;);

// note that $result is a single object, not an array of objects
echo $result-&gt;bug_description;
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.select.fetchone"><div class="info"><h1 class="title">Fetching a Single Scalar from a Result Set</h1></div>
            

            <p class="para">
                The  <span class="methodname">fetchOne()</span> method is like a combination
                of  <span class="methodname">fetchRow()</span> with  <span class="methodname">fetchCol()</span>,
                in that it returns data only for the first row fetched from
                the result set, and it returns only the value of the first
                column in that row. Therefore it returns only a single
                scalar value, not an array or an object.
            </p>

            <div class="example" id="zend.db.adapter.select.fetchone.example"><div class="info"><p><b>Example #16 Using fetchOne()</b></p></div>
                

                <pre class="programlisting brush: php">
$result = $db-&gt;fetchOne(&#039;SELECT bug_status FROM bugs WHERE bug_id = 2&#039;);

// this is a single string value
echo $result;
</pre>

            </div>
        </div>
    </div>

    <div class="section" id="zend.db.adapter.write"><div class="info"><h1 class="title">Writing Changes to the Database</h1></div>
        

        <p class="para">
            You can use the Adapter class to write new data or change existing
            data in your database. This section describes methods to do these
            operations.
        </p>

        <div class="section" id="zend.db.adapter.write.insert"><div class="info"><h1 class="title">Inserting Data</h1></div>
            

            <p class="para">
                You can add new rows to a table in your database using the
                 <span class="methodname">insert()</span> method. The first argument is a string
                that names the table, and the second argument is an associative
                array, mapping column names to data values.
            </p>

            <div class="example" id="zend.db.adapter.write.insert.example"><div class="info"><p><b>Example #17 Inserting in a Table</b></p></div>
                

                <pre class="programlisting brush: php">
$data = array(
    &#039;created_on&#039;      =&gt; &#039;2007-03-22&#039;,
    &#039;bug_description&#039; =&gt; &#039;Something wrong&#039;,
    &#039;bug_status&#039;      =&gt; &#039;NEW&#039;
);

$db-&gt;insert(&#039;bugs&#039;, $data);
</pre>

            </div>

            <p class="para">
                Columns you exclude from the array of data are not specified to
                the database. Therefore, they follow the same rules that an
                <acronym class="acronym">SQL</acronym> <acronym class="acronym">INSERT</acronym> statement follows: if the column
                has a <acronym class="acronym">DEFAULT</acronym> clause, the column takes that value in the row
                created, otherwise the column is left in a <b><tt>NULL</tt></b> state.
            </p>

            <p class="para">
                By default, the values in your data array are inserted using
                parameters. This reduces risk of some types of security
                issues. You don&#039;t need to apply escaping or quoting to values
                in the data array.
            </p>

            <p class="para">
                You might need values in the data array to be treated as <acronym class="acronym">SQL</acronym>
                expressions, in which case they should not be quoted. By
                default, all data values passed as strings are treated as
                string literals. To specify that the value is an <acronym class="acronym">SQL</acronym>
                expression and therefore should not be quoted, pass the value
                in the data array as an object of type <span class="classname">Zend_Db_Expr</span> instead
                of a plain string.
            </p>

            <div class="example" id="zend.db.adapter.write.insert.example2"><div class="info"><p><b>Example #18 Inserting Expressions in a Table</b></p></div>
                

                <pre class="programlisting brush: php">
$data = array(
    &#039;created_on&#039;      =&gt; new Zend_Db_Expr(&#039;CURDATE()&#039;),
    &#039;bug_description&#039; =&gt; &#039;Something wrong&#039;,
    &#039;bug_status&#039;      =&gt; &#039;NEW&#039;
);

$db-&gt;insert(&#039;bugs&#039;, $data);
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.write.lastinsertid"><div class="info"><h1 class="title">Retrieving a Generated Value</h1></div>
            

            <p class="para">
                Some <acronym class="acronym">RDBMS</acronym> brands support auto-incrementing primary keys.
                A table defined this way generates a primary key value
                automatically during an <acronym class="acronym">INSERT</acronym> of a new row. The return value
                of the  <span class="methodname">insert()</span> method is <em class="emphasis">not</em>
                the last inserted ID, because the table might not have an
                auto-incremented column. Instead, the return value is the
                number of rows affected (usually 1).
            </p>

            <p class="para">
                If your table is defined with an auto-incrementing primary key,
                you can call the  <span class="methodname">lastInsertId()</span> method after the
                insert. This method returns the last value generated in the
                scope of the current database connection.
            </p>

            <div class="example" id="zend.db.adapter.write.lastinsertid.example-1"><div class="info"><p><b>Example #19 Using lastInsertId() for an Auto-Increment Key</b></p></div>
                

                <pre class="programlisting brush: php">
$db-&gt;insert(&#039;bugs&#039;, $data);

// return the last value generated by an auto-increment column
$id = $db-&gt;lastInsertId();
</pre>

            </div>

            <p class="para">
                Some <acronym class="acronym">RDBMS</acronym> brands support a sequence object, which generates
                unique values to serve as primary key values. To support
                sequences, the  <span class="methodname">lastInsertId()</span> method accepts two
                optional string arguments. These arguments name the table and
                the column, assuming you have followed the convention that a
                sequence is named using the table and column names for which
                the sequence generates values, and a suffix &quot;_seq&quot;. This is
                based on the convention used by PostgreSQL when naming
                sequences for <b><tt>SERIAL</tt></b> columns. For example, a table &quot;bugs&quot; with
                primary key column &quot;bug_id&quot; would use a sequence named
                &quot;bugs_bug_id_seq&quot;.
            </p>

            <div class="example" id="zend.db.adapter.write.lastinsertid.example-2"><div class="info"><p><b>Example #20 Using lastInsertId() for a Sequence</b></p></div>
                

                <pre class="programlisting brush: php">
$db-&gt;insert(&#039;bugs&#039;, $data);

// return the last value generated by sequence &#039;bugs_bug_id_seq&#039;.
$id = $db-&gt;lastInsertId(&#039;bugs&#039;, &#039;bug_id&#039;);

// alternatively, return the last value generated by sequence &#039;bugs_seq&#039;.
$id = $db-&gt;lastInsertId(&#039;bugs&#039;);
</pre>

            </div>

            <p class="para">
                If the name of your sequence object does not follow this naming
                convention, use the  <span class="methodname">lastSequenceId()</span> method
                instead. This method takes a single string argument, naming
                the sequence literally.
            </p>

            <div class="example" id="zend.db.adapter.write.lastinsertid.example-3"><div class="info"><p><b>Example #21 Using lastSequenceId()</b></p></div>
                

                <pre class="programlisting brush: php">
$db-&gt;insert(&#039;bugs&#039;, $data);

// return the last value generated by sequence &#039;bugs_id_gen&#039;.
$id = $db-&gt;lastSequenceId(&#039;bugs_id_gen&#039;);
</pre>

            </div>

            <p class="para">
                For <acronym class="acronym">RDBMS</acronym> brands that don&#039;t support sequences, including MariaDB,
        MySQL, Microsoft <acronym class="acronym">SQL</acronym> Server, and SQLite, the arguments to the
                 <span class="methodname">lastInsertId()</span> method are ignored, and the value returned
                is the most recent value generated for any table by <acronym class="acronym">INSERT</acronym>
                operations during the current connection. For these <acronym class="acronym">RDBMS</acronym> brands,
                the  <span class="methodname">lastSequenceId()</span> method always returns
                <b><tt>NULL</tt></b>.
            </p>

            <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Why Not Use &quot;SELECT MAX(id) FROM table&quot;?</b><br /></span>
                

                <p class="para">
                    Sometimes this query returns the most recent primary key
                    value inserted into the table. However, this technique
                    is not safe to use in an environment where multiple clients are
                    inserting records to the database. It is possible, and
                    therefore is bound to happen eventually, that another
                    client inserts another row in the instant between the
                    insert performed by your client application and your query
                    for the  <span class="methodname">MAX(id)</span> value. Thus the value returned does
                    not identify the row you inserted, it identifies the row
                    inserted by some other client. There is no way to know
                    when this has happened.
                </p>

                <p class="para">
                    Using a strong transaction isolation mode such as
                    &quot;repeatable read&quot; can mitigate this risk, but some <acronym class="acronym">RDBMS</acronym>
                    brands don&#039;t support the transaction isolation required for
                    this, or else your application may use a lower transaction
                    isolation mode by design.
                </p>

                <p class="para">
                    Furthermore, using an expression like &quot;<strong class="command">MAX(id)+1</strong>&quot; to generate
                    a new value for a primary key is not safe, because two clients
                    could do this query simultaneously, and then both use the same
                    calculated value for their next <acronym class="acronym">INSERT</acronym> operation.
                </p>

                <p class="para">
                    All <acronym class="acronym">RDBMS</acronym> brands provide mechanisms to generate unique
                    values, and to return the last value generated. These
                    mechanisms necessarily work outside of the scope of
                    transaction isolation, so there is no chance of two clients
                    generating the same value, and there is no chance that the
                    value generated by another client could be reported to your
                    client&#039;s connection as the last value generated.
                </p>
            </p></blockquote>
        </div>

        <div class="section" id="zend.db.adapter.write.update"><div class="info"><h1 class="title">Updating Data</h1></div>
            

            <p class="para">
                You can update rows in a database table using the
                 <span class="methodname">update()</span> method of an Adapter. This method takes
                three arguments: the first is the name of the table; the
                second is an associative array mapping columns to change to new
                values to assign to these columns.
            </p>

            <p class="para">
                The values in the data array are treated as string literals.
                See <a href="zend.db.adapter.html#zend.db.adapter.write.insert" class="link">this section</a>
                for information on using <acronym class="acronym">SQL</acronym> expressions in the data array.
            </p>

            <p class="para">
                The third argument is a string containing an <acronym class="acronym">SQL</acronym> expression
                that is used as criteria for the rows to change. The values
                and identifiers in this argument are not quoted or escaped.
                You are responsible for ensuring that any dynamic content is
                interpolated into this string safely.
                See <a href="zend.db.adapter.html#zend.db.adapter.quoting" class="link">this section</a>
                for methods to help you do this.
            </p>

            <p class="para">
                The return value is the number of rows affected by the update
                operation.
            </p>

            <div class="example" id="zend.db.adapter.write.update.example"><div class="info"><p><b>Example #22 Updating Rows</b></p></div>
                

                <pre class="programlisting brush: php">
$data = array(
    &#039;updated_on&#039;      =&gt; &#039;2007-03-23&#039;,
    &#039;bug_status&#039;      =&gt; &#039;FIXED&#039;
);

$n = $db-&gt;update(&#039;bugs&#039;, $data, &#039;bug_id = 2&#039;);
</pre>

            </div>

            <p class="para">
                If you omit the third argument, then all rows in the database
                table are updated with the values specified in the data array.
            </p>

            <p class="para">
                If you provide an array of strings as the third argument, these
                strings are joined together as terms in an expression separated
                by <b><tt>AND</tt></b> operators.
            </p>

            <p class="para">
                If you provide an array of arrays as the third argument, the
                values will be automatically quoted into the keys. These
                will then be joined together as terms, separated by
                <b><tt>AND</tt></b> operators.
            </p>

            <div class="example" id="zend.db.adapter.write.update.example-array"><div class="info"><p><b>Example #23 Updating Rows Using an Array of Expressions</b></p></div>
                

                <pre class="programlisting brush: php">
$data = array(
    &#039;updated_on&#039;      =&gt; &#039;2007-03-23&#039;,
    &#039;bug_status&#039;      =&gt; &#039;FIXED&#039;
);

$where[] = &quot;reported_by = &#039;goofy&#039;&quot;;
$where[] = &quot;bug_status = &#039;OPEN&#039;&quot;;

$n = $db-&gt;update(&#039;bugs&#039;, $data, $where);

// Resulting SQL is:
//  UPDATE &quot;bugs&quot; SET &quot;update_on&quot; = &#039;2007-03-23&#039;, &quot;bug_status&quot; = &#039;FIXED&#039;
//  WHERE (&quot;reported_by&quot; = &#039;goofy&#039;) AND (&quot;bug_status&quot; = &#039;OPEN&#039;)
</pre>

            </div>

            <div class="example" id="zend.db.adapter.write.update.example-arrayofarrays"><div class="info"><p><b>Example #24 Updating Rows Using an Array of Arrays</b></p></div>
                

                <pre class="programlisting brush: php">
$data = array(
    &#039;updated_on&#039;      =&gt; &#039;2007-03-23&#039;,
    &#039;bug_status&#039;      =&gt; &#039;FIXED&#039;
);

$where[&#039;reported_by = ?&#039;] = &#039;goofy&#039;;
$where[&#039;bug_status = ?&#039;]  = &#039;OPEN&#039;;

$n = $db-&gt;update(&#039;bugs&#039;, $data, $where);

// Resulting SQL is:
//  UPDATE &quot;bugs&quot; SET &quot;update_on&quot; = &#039;2007-03-23&#039;, &quot;bug_status&quot; = &#039;FIXED&#039;
//  WHERE (&quot;reported_by&quot; = &#039;goofy&#039;) AND (&quot;bug_status&quot; = &#039;OPEN&#039;)
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.write.delete"><div class="info"><h1 class="title">Deleting Data</h1></div>
            

            <p class="para">
                You can delete rows from a database table using the
                 <span class="methodname">delete()</span> method. This method takes two arguments:
                the first is a string naming the table.
            </p>

            <p class="para">
                The second argument is a string containing an <acronym class="acronym">SQL</acronym> expression
                that is used as criteria for the rows to delete. The values
                and identifiers in this argument are not quoted or escaped.
                You are responsible for ensuring that any dynamic content is
                interpolated into this string safely.
                See <a href="zend.db.adapter.html#zend.db.adapter.quoting" class="link"> this section</a>
                for methods to help you do this.
            </p>

            <p class="para">
                The return value is the number of rows affected by the delete
                operation.
            </p>

            <div class="example" id="zend.db.adapter.write.delete.example"><div class="info"><p><b>Example #25 Deleting Rows</b></p></div>
                

                <pre class="programlisting brush: php">
$n = $db-&gt;delete(&#039;bugs&#039;, &#039;bug_id = 3&#039;);
</pre>

            </div>

            <p class="para">
                If you omit the second argument, the result is that all rows in
                the database table are deleted.
            </p>

            <p class="para">
                If you provide an array of strings as the second argument, these
                strings are joined together as terms in an expression separated
                by <b><tt>AND</tt></b> operators.
            </p>

            <p class="para">
                If you provide an array of arrays as the second argument, the
                values will be automatically quoted into the keys. These
                will then be joined together as terms, separated by
                <b><tt>AND</tt></b> operators.
            </p>
        </div>
    </div>

    <div class="section" id="zend.db.adapter.quoting"><div class="info"><h1 class="title">Quoting Values and Identifiers</h1></div>
        

        <p class="para">
            When you form <acronym class="acronym">SQL</acronym> queries, often it is the case that you need to
            include the values of <acronym class="acronym">PHP</acronym> variables in <acronym class="acronym">SQL</acronym>
            expressions. This is risky, because if the value in a <acronym class="acronym">PHP</acronym> string
            contains certain symbols, such as the quote symbol, it could result in invalid
            <acronym class="acronym">SQL</acronym>. For example, notice the imbalanced quote characters in the
            following query:
        </p>

        <pre class="programlisting brush: php">
$name = &quot;O&#039;Reilly&quot;;
$sql = &quot;SELECT * FROM bugs WHERE reported_by = &#039;$name&#039;&quot;;

echo $sql;
// SELECT * FROM bugs WHERE reported_by = &#039;O&#039;Reilly&#039;
</pre>


        <p class="para">
            Even worse is the risk that such code mistakes might be exploited
            deliberately by a person who is trying to manipulate the function
            of your web application. If they can specify the value of a <acronym class="acronym">PHP</acronym>
            variable through the use of an <acronym class="acronym">HTTP</acronym> parameter or other mechanism,
            they might be able to make your <acronym class="acronym">SQL</acronym> queries do things that you
            didn&#039;t intend them to do, such as return data to which the person
            should not have privilege to read. This is a serious and widespread
            technique for violating application security, known as &quot;SQL Injection&quot; (see <a href="http://en.wikipedia.org/wiki/SQL_Injection" class="link external">&raquo; http://en.wikipedia.org/wiki/SQL_Injection</a>).
        </p>

        <p class="para">
            The <span class="classname">Zend_Db</span> Adapter class provides convenient functions to help
            you reduce vulnerabilities to <acronym class="acronym">SQL</acronym> Injection attacks in your
            <acronym class="acronym">PHP</acronym> code. The solution is to escape special characters such as quotes
            in <acronym class="acronym">PHP</acronym> values before they are interpolated into your
            <acronym class="acronym">SQL</acronym> strings. This protects against both accidental and deliberate
            manipulation of <acronym class="acronym">SQL</acronym> strings by <acronym class="acronym">PHP</acronym> variables that
            contain special characters.
        </p>

        <div class="section" id="zend.db.adapter.quoting.quote"><div class="info"><h1 class="title">Using quote()</h1></div>
            

            <p class="para">
                The  <span class="methodname">quote()</span> method accepts a single argument, a
                scalar string value. It returns the value with special
                characters escaped in a manner appropriate for the <acronym class="acronym">RDBMS</acronym> you
                are using, and surrounded by string value delimiters. The
                standard <acronym class="acronym">SQL</acronym> string value delimiter is the single-quote
                (&#039;).
            </p>

            <div class="example" id="zend.db.adapter.quoting.quote.example"><div class="info"><p><b>Example #26 Using quote()</b></p></div>
                

                <pre class="programlisting brush: php">
$name = $db-&gt;quote(&quot;O&#039;Reilly&quot;);
echo $name;
// &#039;O\&#039;Reilly&#039;

$sql = &quot;SELECT * FROM bugs WHERE reported_by = $name&quot;;

echo $sql;
// SELECT * FROM bugs WHERE reported_by = &#039;O\&#039;Reilly&#039;
</pre>

            </div>

            <p class="para">
                Note that the return value of  <span class="methodname">quote()</span> includes the
                quote delimiters around the string. This is different from
                some functions that escape special characters but do not add
                the quote delimiters, for example <a href="http://www.php.net/mysqli_real_escape_string" class="link external">&raquo; mysql_real_escape_string()</a>.
            </p>

            <p class="para">
                Values may need to be quoted or not quoted according to the <acronym class="acronym">SQL</acronym>
                datatype context in which they are used. For instance, in some
                <acronym class="acronym">RDBMS</acronym> brands, an integer value must not be quoted as a string
                if it is compared to an integer-type column or expression.
                In other words, the following is an error in some <acronym class="acronym">SQL</acronym>
                implementations, assuming <span class="property">intColumn</span> has a
                <acronym class="acronym">SQL</acronym> datatype of <b><tt>INTEGER</tt></b>
            </p>

            <pre class="programlisting brush: php">
SELECT * FROM atable WHERE intColumn = &#039;123&#039;
</pre>


            <p class="para">
                You can use the optional second argument to the
                 <span class="methodname">quote()</span> method to apply quoting selectively for
                the <acronym class="acronym">SQL</acronym> datatype you specify.
            </p>

            <div class="example" id="zend.db.adapter.quoting.quote.example-2"><div class="info"><p><b>Example #27 Using quote() with a SQL Type</b></p></div>
                

                <pre class="programlisting brush: php">
$value = &#039;1234&#039;;
$sql = &#039;SELECT * FROM atable WHERE intColumn = &#039;
     . $db-&gt;quote($value, &#039;INTEGER&#039;);
</pre>

            </div>

            <p class="para">
                Each <span class="classname">Zend_Db_Adapter</span> class has encoded the names of numeric
                <acronym class="acronym">SQL</acronym> datatypes for the respective brand of
                <acronym class="acronym">RDBMS</acronym>. You can also use the constants
                <b><tt>Zend_Db::INT_TYPE</tt></b>, <b><tt>Zend_Db::BIGINT_TYPE</tt></b>,
                and <b><tt>Zend_Db::FLOAT_TYPE</tt></b> to write code in a more
                <acronym class="acronym">RDBMS</acronym>-independent way.
            </p>

            <p class="para">
                <span class="classname">Zend_Db_Table</span> specifies <acronym class="acronym">SQL</acronym> types to
                 <span class="methodname">quote()</span> automatically when generating
                <acronym class="acronym">SQL</acronym> queries that reference a table&#039;s key columns.
            </p>
        </div>

        <div class="section" id="zend.db.adapter.quoting.quote-into"><div class="info"><h1 class="title">Using quoteInto()</h1></div>
            

            <p class="para">
                The most typical usage of quoting is to interpolate a <acronym class="acronym">PHP</acronym>
                variable into a <acronym class="acronym">SQL</acronym> expression or statement. You can use the
                 <span class="methodname">quoteInto()</span> method to do this in one step. This
                method takes two arguments: the first argument is a string
                containing a placeholder symbol (?), and the
                second argument is a value or <acronym class="acronym">PHP</acronym> variable that should be
                substituted for that placeholder.
            </p>

            <p class="para">
                The placeholder symbol is the same symbol used by many <acronym class="acronym">RDBMS</acronym>
                brands for positional parameters, but the
                 <span class="methodname">quoteInto()</span> method only emulates query parameters.
                The method simply interpolates the value into the string,
                escapes special characters, and applies quotes around it.
                True query parameters maintain the separation between the <acronym class="acronym">SQL</acronym>
                string and the parameters as the statement is parsed in the
                <acronym class="acronym">RDBMS</acronym> server.
            </p>

            <div class="example" id="zend.db.adapter.quoting.quote-into.example"><div class="info"><p><b>Example #28 Using quoteInto()</b></p></div>
                

                <pre class="programlisting brush: php">
$sql = $db-&gt;quoteInto(&quot;SELECT * FROM bugs WHERE reported_by = ?&quot;, &quot;O&#039;Reilly&quot;);

echo $sql;
// SELECT * FROM bugs WHERE reported_by = &#039;O\&#039;Reilly&#039;
</pre>

            </div>

            <p class="para">
                You can use the optional third parameter of
                 <span class="methodname">quoteInto()</span> to specify the <acronym class="acronym">SQL</acronym> datatype.
                Numeric datatypes are not quoted, and other types are quoted.
            </p>

            <div class="example" id="zend.db.adapter.quoting.quote-into.example-2"><div class="info"><p><b>Example #29 Using quoteInto() with a SQL Type</b></p></div>
                

                <pre class="programlisting brush: php">
$sql = $db
    -&gt;quoteInto(&quot;SELECT * FROM bugs WHERE bug_id = ?&quot;, &#039;1234&#039;, &#039;INTEGER&#039;);

echo $sql;
// SELECT * FROM bugs WHERE reported_by = 1234
</pre>

            </div>
        </div>

        <div class="section" id="zend.db.adapter.quoting.quote-identifier"><div class="info"><h1 class="title">Using quoteIdentifier()</h1></div>
            

            <p class="para">
                Values are not the only part of <acronym class="acronym">SQL</acronym> syntax that might need to
                be variable. If you use <acronym class="acronym">PHP</acronym> variables to name tables, columns,
                or other identifiers in your <acronym class="acronym">SQL</acronym> statements, you might need to
                quote these strings too. By default, <acronym class="acronym">SQL</acronym> identifiers have
                syntax rules like <acronym class="acronym">PHP</acronym> and most other programming languages.
                For example, identifiers should not contain spaces, certain
                punctuation or special characters, or international characters.
                Also certain words are reserved for <acronym class="acronym">SQL</acronym> syntax, and should not
                be used as identifiers.
            </p>

            <p class="para">
                However, <acronym class="acronym">SQL</acronym> has a feature called
                <em class="emphasis">delimited identifiers</em>, which allows broader choices for the
                spelling of identifiers. If you enclose a <acronym class="acronym">SQL</acronym> identifier in the
                proper types of quotes, you can use identifiers with spellings that would be invalid
                without the quotes. Delimited identifiers can contain spaces,
                punctuation, or international characters. You can also use <acronym class="acronym">SQL</acronym>
                reserved words if you enclose them in identifier delimiters.
            </p>

            <p class="para">
                The  <span class="methodname">quoteIdentifier()</span> method works like
                 <span class="methodname">quote()</span>, but it applies the identifier delimiter
                characters to the string according to the type of Adapter you
                use. For example, standard <acronym class="acronym">SQL</acronym> uses double-quotes
                (&quot;) for identifier delimiters, and most <acronym class="acronym">RDBMS</acronym>
                brands use that symbol. MySQL uses back-quotes (`) by default. The
                 <span class="methodname">quoteIdentifier()</span> method also escapes special
                characters within the string argument.
            </p>

            <div class="example" id="zend.db.adapter.quoting.quote-identifier.example"><div class="info"><p><b>Example #30 Using quoteIdentifier()</b></p></div>
                

                <pre class="programlisting brush: php">
// we might have a table name that is an SQL reserved word
$tableName = $db-&gt;quoteIdentifier(&quot;order&quot;);

$sql = &quot;SELECT * FROM $tableName&quot;;

echo $sql
// SELECT * FROM &quot;order&quot;
</pre>

            </div>

            <p class="para">
                <acronym class="acronym">SQL</acronym> delimited identifiers are case-sensitive, unlike unquoted
                identifiers. Therefore, if you use delimited identifiers, you
                must use the spelling of the identifier exactly as it is stored
                in your schema, including the case of the letters.
            </p>

            <p class="para">
                In most cases where <acronym class="acronym">SQL</acronym> is generated within
                <span class="classname">Zend_Db</span> classes, the default is that all identifiers are
                delimited automatically. You can change this behavior with the option
                <b><tt>Zend_Db::AUTO_QUOTE_IDENTIFIERS</tt></b>. Specify this
                when instantiating the Adapter.
                See <a href="zend.db.adapter.html#zend.db.adapter.connecting.parameters.example2" class="link">this
                    example</a>.
            </p>
        </div>
    </div>

    <div class="section" id="zend.db.adapter.transactions"><div class="info"><h1 class="title">Controlling Database Transactions</h1></div>
        

        <p class="para">
            Databases define transactions as logical units of work that can be
            committed or rolled back as a single change, even if they operate
            on multiple tables. All queries to a database are executed within
            the context of a transaction, even if the database driver manages
            them implicitly. This is called <em class="emphasis">auto-commit</em>
            mode, in which the database driver creates a transaction for every
            statement you execute, and commits that transaction after your
            <acronym class="acronym">SQL</acronym> statement has been executed. By default, all
            <span class="classname">Zend_Db</span> Adapter classes operate in auto-commit mode.
        </p>

        <p class="para">
            Alternatively, you can specify the beginning and resolution of a
            transaction, and thus control how many <acronym class="acronym">SQL</acronym> queries are included in
            a single group that is committed (or rolled back) as a single
            operation. Use the  <span class="methodname">beginTransaction()</span> method to
            initiate a transaction. Subsequent <acronym class="acronym">SQL</acronym> statements are executed in
            the context of the same transaction until you resolve it
            explicitly.
        </p>

        <p class="para">
            To resolve the transaction, use either the  <span class="methodname">commit()</span> or
             <span class="methodname">rollBack()</span> methods. The  <span class="methodname">commit()</span>
            method marks changes made during your transaction as committed, which
            means the effects of these changes are shown in queries run in
            other transactions.
        </p>

        <p class="para">
            The  <span class="methodname">rollBack()</span> method does the opposite: it discards
            the changes made during your transaction. The changes are
            effectively undone, and the state of the data returns to how it was
            before you began your transaction. However, rolling back your
            transaction has no effect on changes made by other transactions
            running concurrently.
        </p>

        <p class="para">
            After you resolve this transaction, <span class="classname">Zend_Db_Adapter</span>
            returns to auto-commit mode until you call
             <span class="methodname">beginTransaction()</span> again.
        </p>

        <div class="example" id="zend.db.adapter.transactions.example"><div class="info"><p><b>Example #31 Managing a Transaction to Ensure Consistency</b></p></div>
            

            <pre class="programlisting brush: php">
// Start a transaction explicitly.
$db-&gt;beginTransaction();

try {
    // Attempt to execute one or more queries:
    $db-&gt;query(...);
    $db-&gt;query(...);
    $db-&gt;query(...);

    // If all succeed, commit the transaction and all changes
    // are committed at once.
    $db-&gt;commit();

} catch (Exception $e) {
    // If any of the queries failed and threw an exception,
    // we want to roll back the whole transaction, reversing
    // changes made in the transaction, even those that succeeded.
    // Thus all changes are committed together, or none are.
    $db-&gt;rollBack();
    echo $e-&gt;getMessage();
}
</pre>

        </div>
    </div>

    <div class="section" id="zend.db.adapter.list-describe"><div class="info"><h1 class="title">Listing and Describing Tables</h1></div>
        

        <p class="para">
            The  <span class="methodname">listTables()</span> method returns an array of strings,
            naming all tables in the current database.
        </p>

        <p class="para">
            The  <span class="methodname">describeTable()</span> method returns an associative
            array of metadata about a table. Specify the name of the table
            as a string in the first argument to this method. The second
            argument is optional, and names the schema in which the table
            exists.
        </p>

        <p class="para">
            The keys of the associative array returned are the column names of
            the table. The value corresponding to each column is also an
            associative array, with the following keys and values:
        </p>

        <table id="zend.db.adapter.list-describe.metadata" class="doctable table"><div class="info"><caption><b>Metadata Fields Returned by describeTable()</b></caption></div>
            

            
                <thead valign="middle">
                    <tr valign="middle">
                        <th>Key</th>
                        <th>Type</th>
                        <th>Description</th>
                    </tr>

                </thead>


                <tbody valign="middle" class="tbody">
                    <tr valign="middle">
                        <td align="left"><b><tt>SCHEMA_NAME</tt></b></td>
                        <td align="left">(string)</td>
                        <td align="left">Name of the database schema in which this table exists.</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>TABLE_NAME</tt></b></td>
                        <td align="left">(string)</td>
                        <td align="left">Name of the table to which this column belongs.</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>COLUMN_NAME</tt></b></td>
                        <td align="left">(string)</td>
                        <td align="left">Name of the column.</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>COLUMN_POSITION</tt></b></td>
                        <td align="left">(integer)</td>
                        <td align="left">Ordinal position of the column in the table.</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>DATA_TYPE</tt></b></td>
                        <td align="left">(string)</td>
                        <td align="left"><acronym class="acronym">RDBMS</acronym> name of the datatype of the column.</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>DEFAULT</tt></b></td>
                        <td align="left">(string)</td>
                        <td align="left">Default value for the column, if any.</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>NULLABLE</tt></b></td>
                        <td align="left">(boolean)</td>

                        <td align="left">
                            <b><tt>TRUE</tt></b> if the column accepts <acronym class="acronym">SQL</acronym>
                            <b><tt>NULL</tt></b>&#039;s, <b><tt>FALSE</tt></b> if the
                            column has a <b><tt>NOT</tt></b> <b><tt>NULL</tt></b>
                            constraint.
                        </td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>LENGTH</tt></b></td>
                        <td align="left">(integer)</td>

                        <td align="left">
                            Length or size of the column as reported by the
                            <acronym class="acronym">RDBMS</acronym>.
                        </td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>SCALE</tt></b></td>
                        <td align="left">(integer)</td>

                        <td align="left">
                            Scale of <acronym class="acronym">SQL</acronym> <b><tt>NUMERIC</tt></b> or
                            <b><tt>DECIMAL</tt></b> type.
                        </td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>PRECISION</tt></b></td>
                        <td align="left">(integer)</td>

                        <td align="left">
                            Precision of <acronym class="acronym">SQL</acronym> <b><tt>NUMERIC</tt></b> or
                            <b><tt>DECIMAL</tt></b> type.
                        </td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>UNSIGNED</tt></b></td>
                        <td align="left">(boolean)</td>

                        <td align="left">
                            <b><tt>TRUE</tt></b> if an integer-based type is reported as
                            <b><tt>UNSIGNED</tt></b>.
                        </td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>PRIMARY</tt></b></td>
                        <td align="left">(boolean)</td>

                        <td align="left">
                            <b><tt>TRUE</tt></b> if the column is part of the primary key of
                            this table.
                        </td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>PRIMARY_POSITION</tt></b></td>
                        <td align="left">(integer)</td>
                        <td align="left">Ordinal position (1-based) of the column in the primary key.</td>
                    </tr>


                    <tr valign="middle">
                        <td align="left"><b><tt>IDENTITY</tt></b></td>
                        <td align="left">(boolean)</td>

                        <td align="left">
                            <b><tt>TRUE</tt></b> if the column uses an auto-generated value.
                        </td>
                    </tr>

                </tbody>
            
        </table>


        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>How the IDENTITY Metadata Field Relates to Specific RDBMSs</b><br /></span>
            

            <p class="para">
                The <b><tt>IDENTITY</tt></b> metadata field was chosen as an &#039;idiomatic&#039; term
                to represent a relation to surrogate keys. This field can be
                commonly known by the following values:-
            </p>

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        <b><tt>IDENTITY</tt></b> - <acronym class="acronym">DB2</acronym>,
                        <acronym class="acronym">MSSQL</acronym>
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <b><tt>AUTO_INCREMENT</tt></b> - MySQL/MariaDB
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <b><tt>SERIAL</tt></b> - PostgreSQL
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <b><tt>SEQUENCE</tt></b> - Oracle
                    </p>
                </li>
            </ul>
        </p></blockquote>

        <p class="para">
            If no table exists matching the table name and optional schema name
            specified, then  <span class="methodname">describeTable()</span> returns an empty array.
        </p>
    </div>

    <div class="section" id="zend.db.adapter.closing"><div class="info"><h1 class="title">Closing a Connection</h1></div>
        

        <p class="para">
            Normally it is not necessary to close a database connection. <acronym class="acronym">PHP</acronym>
            automatically cleans up all resources and the end of a request.
            Database extensions are designed to close the connection as the
            reference to the resource object is cleaned up.
        </p>

        <p class="para">
            However, if you have a long-duration <acronym class="acronym">PHP</acronym> script that initiates many
            database connections, you might need to close the connection, to avoid
            exhausting the capacity of your <acronym class="acronym">RDBMS</acronym> server. You can use the
            Adapter&#039;s  <span class="methodname">closeConnection()</span> method to explicitly close
            the underlying database connection.
        </p>

        <p class="para">
            Since release 1.7.2, you could check you are currently connected to the
            <acronym class="acronym">RDBMS</acronym> server with the method  <span class="methodname">isConnected()</span>.
            This means that a connection resource has been initiated and wasn&#039;t closed. This
            function is not currently able to test for example a server side closing of the
            connection. This is internally use to close the connection. It allow you to close the
            connection multiple times without errors. It was already the case before 1.7.2 for
            <acronym class="acronym">PDO</acronym> adapters but not for the others.
        </p>

        <div class="example" id="zend.db.adapter.closing.example"><div class="info"><p><b>Example #32 Closing a Database Connection</b></p></div>
            

            <pre class="programlisting brush: php">
$db-&gt;closeConnection();
</pre>

        </div>

        <blockquote class="note"><p><b class="note">Note</b>: <span class="info"><b>Does Zend_Db Support Persistent Connections?</b><br /></span>
            

            <p class="para">
                Yes, persistence is supported through the addition of
                the <span class="property">persistent</span> flag set to <b><tt>TRUE</tt></b> in the
                configuration (not driver_configuration) of an adapter
                in <span class="classname">Zend_Db</span>.
            </p>

            <div class="example" id="zend.db.adapter.connecting.persistence.example"><div class="info"><p><b>Example #33 Using the Persitence Flag with the Oracle Adapter</b></p></div>
                

                <pre class="programlisting brush: php">
$db = Zend_Db::factory(&#039;Oracle&#039;, array(
    &#039;host&#039;       =&gt; &#039;127.0.0.1&#039;,
    &#039;username&#039;   =&gt; &#039;webuser&#039;,
    &#039;password&#039;   =&gt; &#039;xxxxxxxx&#039;,
    &#039;dbname&#039;     =&gt; &#039;test&#039;,
    &#039;persistent&#039; =&gt; true
));
</pre>

            </div>

            <p class="para">
                Please note that using persistent connections can cause an
                excess of idle connections on the <acronym class="acronym">RDBMS</acronym> server, which causes
                more problems than any performance gain you might achieve by
                reducing the overhead of making connections.
            </p>

            <p class="para">
                Database connections have state. That is, some objects in the
                <acronym class="acronym">RDBMS</acronym> server exist in session scope. Examples are locks, user
                variables, temporary tables, and information about the most
                recently executed query, such as rows affected, and last
                generated id value. If you use persistent connections, your
                application could access invalid or privileged data that were
                created in a previous <acronym class="acronym">PHP</acronym> request.
            </p>

            <p class="para">
                Currently, only Oracle, <acronym class="acronym">DB2</acronym>, and the <acronym class="acronym">PDO</acronym>
                adapters (where specified by <acronym class="acronym">PHP</acronym>) support persistence in
                <span class="classname">Zend_Db</span>.
            </p>
        </p></blockquote>
    </div>

    <div class="section" id="zend.db.adapter.other-statements"><div class="info"><h1 class="title">Running Other Database Statements</h1></div>
        

        <p class="para">
            There might be cases in which you need to access the connection
            object directly, as provided by the <acronym class="acronym">PHP</acronym> database extension. Some
            of these extensions may offer features that are not surfaced by
            methods of <span class="classname">Zend_Db_Adapter_Abstract</span>.
        </p>

        <p class="para">
            For example, all <acronym class="acronym">SQL</acronym> statements run by <span class="classname">Zend_Db</span>
            are prepared, then executed. However, some database features are incompatible with
            prepared statements. <b><tt>DDL</tt></b> statements like
            <b><tt>CREATE</tt></b> and <b><tt>ALTER</tt></b> cannot be prepared in MySQL.
            Also, <acronym class="acronym">SQL</acronym> statements don&#039;t benefit from the <a href="http://dev.mysql.com/doc/refman/5.1/en/query-cache-how.html" class="link external">&raquo; MySQL Query
                Cache</a>, prior to MySQL 5.1.17.
        </p>

        <p class="para">
            Most <acronym class="acronym">PHP</acronym> database extensions provide a method to execute
            <acronym class="acronym">SQL</acronym> statements without preparing them. For example, in
            <acronym class="acronym">PDO</acronym>, this method is  <span class="methodname">exec()</span>. You can access
            the connection object in the <acronym class="acronym">PHP</acronym> extension directly using
             <span class="methodname">getConnection()</span>.
        </p>

        <div class="example" id="zend.db.adapter.other-statements.example"><div class="info"><p><b>Example #34 Running a Non-Prepared Statement in a PDO Adapter</b></p></div>
            

            <pre class="programlisting brush: php">
$result = $db-&gt;getConnection()-&gt;exec(&#039;DROP TABLE bugs&#039;);
</pre>

        </div>

        <p class="para">
            Similarly, you can access other methods or properties that are
            specific to <acronym class="acronym">PHP</acronym> database extensions. Be aware, though, that by
            doing this you might constrain your application to the interface
            provided by the extension for a specific brand of <acronym class="acronym">RDBMS</acronym>.
        </p>

        <p class="para">
            In future versions of <span class="classname">Zend_Db</span>, there will be opportunities to
            add method entry points for functionality that is common to
            the supported <acronym class="acronym">PHP</acronym> database extensions. This will not affect
            backward compatibility.
        </p>
    </div>

    <div class="section" id="zend.db.adapter.server-version"><div class="info"><h1 class="title">Retrieving Server Version</h1></div>
        

        <p class="para">
            Since release 1.7.2, you could retrieve the server version in <acronym class="acronym">PHP</acronym>
            syntax style to be able to use  <span class="methodname">version_compare()</span>. If the
            information isn&#039;t available, you will receive <b><tt>NULL</tt></b>.
        </p>

        <div class="example" id="zend.db.adapter.server-version.example"><div class="info"><p><b>Example #35 Verifying server version before running a query</b></p></div>
            

            <pre class="programlisting brush: php">
$version = $db-&gt;getServerVersion();
if (!is_null($version)) {
    if (version_compare($version, &#039;5.0.0&#039;, &#039;&gt;=&#039;)) {
        // do something
    } else {
        // do something else
    }
} else {
    // impossible to read server version
}
</pre>

        </div>
    </div>

    <div class="section" id="zend.db.adapter.adapter-notes"><div class="info"><h1 class="title">Notes on Specific Adapters</h1></div>
        

        <p class="para">
            This section lists differences between the Adapter classes of which
            you should be aware.
        </p>

        <div class="section" id="zend.db.adapter.adapter-notes.ibm-db2"><div class="info"><h1 class="title">IBM DB2</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        Specify this Adapter to the  <span class="methodname">factory()</span> method with
                        the name &#039;Db2&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        This Adapter uses the <acronym class="acronym">PHP</acronym> extension
                        <b><tt>IBM_DB2</tt></b>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <acronym class="acronym">IBM</acronym> <acronym class="acronym">DB2</acronym> supports both sequences and
                        auto-incrementing keys. Therefore the arguments to
                         <span class="methodname">lastInsertId()</span> are optional. If you give
                        no arguments, the Adapter returns the last value
                        generated for an auto-increment key. If you give
                        arguments, the Adapter returns the last value generated
                        by the sequence named according to the convention
                        &#039;<em class="emphasis">table</em>_<em class="emphasis">column</em>_seq&#039;.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.db.adapter.adapter-notes.mysqli"><div class="info"><h1 class="title">MySQLi</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        Specify this Adapter to the  <span class="methodname">factory()</span>
                        method with the name &#039;Mysqli&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        This Adapter utilizes the <acronym class="acronym">PHP</acronym> extension mysqli.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        MySQL and MariaDB do not support sequences, so
                         <span class="methodname">lastInsertId()</span> ignores its arguments and
                        always returns the last value generated for an
                        auto-increment key. The  <span class="methodname">lastSequenceId()</span>
                        method returns <b><tt>NULL</tt></b>.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.db.adapter.adapter-notes.oracle"><div class="info"><h1 class="title">Oracle</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        Specify this Adapter to the  <span class="methodname">factory()</span>
                        method with the name &#039;Oracle&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        This Adapter uses the <acronym class="acronym">PHP</acronym> extension oci8.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Oracle does not support auto-incrementing keys, so you
                        should specify the name of a sequence to
                         <span class="methodname">lastInsertId()</span> or
                         <span class="methodname">lastSequenceId()</span>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        The Oracle extension does not support positional
                        parameters. You must use named parameters.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Currently the <b><tt>Zend_Db::CASE_FOLDING</tt></b> option
                        is not supported by the Oracle adapter. To use this
                        option with Oracle, you must use the <acronym class="acronym">PDO</acronym>
                        <acronym class="acronym">OCI</acronym> adapter.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        By default, <acronym class="acronym">LOB</acronym> fields are returned as
                        <acronym class="acronym">OCI</acronym>-Lob objects. You could retrieve them as string for
                        all requests by using driver options &#039;<span class="property">lob_as_string</span>&#039; or
                        for particular request by using
                         <span class="methodname">setLobAsString(boolean)</span> on adapter or on statement.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.db.adapter.adapter-notes.sqlsrv"><div class="info"><h1 class="title">Microsoft SQL Server</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        Specify this Adapter to the  <span class="methodname">factory()</span> method with
                        the name &#039;Sqlsrv&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        This Adapter uses the <acronym class="acronym">PHP</acronym> extension sqlsrv
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Only Microsoft <acronym class="acronym">SQL</acronym> Server 2005 or greater is supported.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Microsoft <acronym class="acronym">SQL</acronym> Server does not support sequences, so
                         <span class="methodname">lastInsertId()</span> ignores primary key argument and
                        returns the last value generated for an auto-increment key if a table name
                        is specified or a last insert query returned id. The
                         <span class="methodname">lastSequenceId()</span> method returns
                        <b><tt>NULL</tt></b>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <span class="classname">Zend_Db_Adapter_Sqlsrv</span> sets
                        <b><tt>QUOTED_IDENTIFIER</tt></b> ON immediately
                        after connecting to a <acronym class="acronym">SQL</acronym> Server database. This makes the
                        driver use the standard <acronym class="acronym">SQL</acronym> identifier delimiter symbol
                        (<em class="emphasis">&quot;</em>) instead of the proprietary square-brackets
                        syntax <acronym class="acronym">SQL</acronym> Server uses for delimiting identifiers.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        You can specify <span class="property">driver_options</span> as a key in the options
                        array. The value can be a anything from here <a href="http://msdn.microsoft.com/en-us/library/cc296161(SQL.90).aspx" class="link external">&raquo; http://msdn.microsoft.com/en-us/library/cc296161(SQL.90).aspx</a>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        You can use  <span class="methodname">setTransactionIsolationLevel()</span> to set
                        isolation level for current connection. The value can be
                        <b><tt>SQLSRV_TXN_READ_UNCOMMITTED</tt></b>,
                        <b><tt>SQLSRV_TXN_READ_COMMITTED</tt></b>,
                        <b><tt>SQLSRV_TXN_REPEATABLE_READ</tt></b>,
                        <b><tt>SQLSRV_TXN_SNAPSHOT</tt></b> or
                        <b><tt>SQLSRV_TXN_SERIALIZABLE</tt></b>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        As of Zend Framework 1.9, the minimal supported build of the
                        <acronym class="acronym">PHP</acronym> <acronym class="acronym">SQL</acronym> Server extension from
                        Microsoft is 1.0.1924.0. and the <acronym class="acronym">MSSQL</acronym> Server Native
                        Client version 9.00.3042.00.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.db.adapter.adapter-notes.pdo-ibm"><div class="info"><h1 class="title">PDO for IBM DB2 and Informix Dynamic Server (IDS)</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        Specify this Adapter to the  <span class="methodname">factory()</span>
                        method with the name &#039;<span class="classname">Pdo_Ibm</span>&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        This Adapter uses the <acronym class="acronym">PHP</acronym> extensions
                        <acronym class="acronym">PDO</acronym> and <b><tt>PDO_IBM</tt></b>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        You must use at least <b><tt>PDO_IBM</tt></b> extension version 1.2.2.
                        If you have an earlier version of this extension, you
                        must upgrade the <b><tt>PDO_IBM</tt></b> extension from
                        <acronym class="acronym">PECL</acronym>.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.db.adapter.adapter-notes.pdo-mssql"><div class="info"><h1 class="title">PDO Microsoft SQL Server</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        Specify this Adapter to the  <span class="methodname">factory()</span>
                        method with the name &#039;<span class="classname">Pdo_Mssql</span>&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        This Adapter uses the <acronym class="acronym">PHP</acronym> extensions pdo and pdo_dblib.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Microsoft <acronym class="acronym">SQL</acronym> Server does not support sequences, so
                         <span class="methodname">lastInsertId()</span> ignores its arguments and
                        always returns the last value generated for an
                        auto-increment key. The  <span class="methodname">lastSequenceId()</span>
                        method returns <b><tt>NULL</tt></b>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        If you are working with unicode strings in an encoding other than
                        <acronym class="acronym">UCS</acronym>-2 (such as <acronym class="acronym">UTF</acronym>-8), you may have to
                        perform a conversion in your application code or store the data in a binary
                        column. Please refer to <a href="http://support.microsoft.com/kb/232580" class="link external">&raquo; Microsoft&#039;s Knowledge
                            Base</a> for more information.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        <span class="classname">Zend_Db_Adapter_Pdo_Mssql</span> sets
                        <b><tt>QUOTED_IDENTIFIER</tt></b> ON immediately
                        after connecting to a <acronym class="acronym">SQL</acronym> Server database. This makes the
                        driver use the standard <acronym class="acronym">SQL</acronym> identifier delimiter symbol
                        (&quot;) instead of the proprietary square-brackets syntax <acronym class="acronym">SQL</acronym>
                        Server uses for delimiting identifiers.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        You can specify <span class="property">pdoType</span> as a key in the
                        options array. The value can be &quot;mssql&quot; (the default),
                        &quot;dblib&quot;, &quot;freetds&quot;, or &quot;sybase&quot;. This option affects
                        the <acronym class="acronym">DSN</acronym> prefix the adapter uses when constructing the
                        <acronym class="acronym">DSN</acronym> string. Both &quot;freetds&quot; and &quot;sybase&quot; imply a prefix
                        of &quot;sybase:&quot;, which is used for the
                        <a href="http://www.freetds.org/" class="link external">&raquo; FreeTDS</a> set
                        of libraries.
                        See also
                        <a href="http://www.php.net/manual/en/ref.pdo-dblib.connection.php" class="link external">&raquo; 
                        http://www.php.net/manual/en/ref.pdo-dblib.connection.php</a>
                        for more information on the <acronym class="acronym">DSN</acronym> prefixes used in this
                        driver.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.db.adapter.adapter-notes.pdo-mysql"><div class="info"><h1 class="title">PDO MySQL</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        Specify this Adapter to the  <span class="methodname">factory()</span>
                        method with the name &#039;<span class="classname">Pdo_Mysql</span>&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        This Adapter uses the <acronym class="acronym">PHP</acronym> extensions pdo and pdo_mysql.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        MySQL and MariaDB do not support sequences, so
                         <span class="methodname">lastInsertId()</span> ignores its arguments and
                        always returns the last value generated for an
                        auto-increment key. The  <span class="methodname">lastSequenceId()</span>
                        method returns <b><tt>NULL</tt></b>.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.db.adapter.adapter-notes.pdo-oci"><div class="info"><h1 class="title">PDO Oracle</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        Specify this Adapter to the  <span class="methodname">factory()</span>
                        method with the name &#039;<span class="classname">Pdo_Oci</span>&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        This Adapter uses the <acronym class="acronym">PHP</acronym> extensions pdo and pdo_oci.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Oracle does not support auto-incrementing keys, so you
                        should specify the name of a sequence to
                         <span class="methodname">lastInsertId()</span> or
                         <span class="methodname">lastSequenceId()</span>.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.db.adapter.adapter-notes.pdo-pgsql"><div class="info"><h1 class="title">PDO PostgreSQL</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        Specify this Adapter to the  <span class="methodname">factory()</span>
                        method with the name &#039;<span class="classname">Pdo_Pgsql</span>&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        This Adapter uses the <acronym class="acronym">PHP</acronym> extensions pdo and pdo_pgsql.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        PostgreSQL supports both sequences and auto-incrementing
                        keys. Therefore the arguments to
                         <span class="methodname">lastInsertId()</span> are optional. If you give
                        no arguments, the Adapter returns the last value
                        generated for an auto-increment key. If you give
                        arguments, the Adapter returns the last value generated
                        by the sequence named according to the convention
                        &#039;<em class="emphasis">table</em>_<em class="emphasis">column</em>_seq&#039;.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.db.adapter.adapter-notes.pdo-sqlite"><div class="info"><h1 class="title">PDO SQLite</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        Specify this Adapter to the  <span class="methodname">factory()</span>
                        method with the name &#039;<span class="classname">Pdo_Sqlite</span>&#039;.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        This Adapter uses the <acronym class="acronym">PHP</acronym> extensions pdo and pdo_sqlite.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        SQLite does not support sequences, so
                         <span class="methodname">lastInsertId()</span> ignores its arguments and
                        always returns the last value generated for an
                        auto-increment key. The  <span class="methodname">lastSequenceId()</span>
                        method returns <b><tt>NULL</tt></b>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        To connect to an SQLite2 database, specify
                        <strong class="command">&#039;sqlite2&#039; =&gt; true</strong> in the array of
                        parameters when creating an instance of the
                        <span class="classname">Pdo_Sqlite</span> Adapter.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        To connect to an in-memory SQLite database,
                        specify <strong class="command">&#039;dbname&#039; =&gt; &#039;:memory:&#039;</strong> in the
                        array of parameters when creating an instance of
                        the <span class="classname">Pdo_Sqlite</span> Adapter.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Older versions of the SQLite driver for <acronym class="acronym">PHP</acronym> do not seem
                        to support the <acronym class="acronym">PRAGMA</acronym> commands necessary to ensure that
                        short column names are used in result sets. If you
                        have problems that your result sets are returned with
                        keys of the form &quot;tablename.columnname&quot; when you do a
                        join query, then you should upgrade to the current
                        version of <acronym class="acronym">PHP</acronym>.
                    </p>
                </li>
            </ul>
        </div>

        <div class="section" id="zend.db.adapter.adapter-notes.firebird"><div class="info"><h1 class="title">Firebird (Interbase)</h1></div>
            

            <ul class="itemizedlist">
                <li class="listitem">
                    <p class="para">
                        This Adapter uses the <acronym class="acronym">PHP</acronym> extension php_interbase.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Firebird (Interbase) does not support auto-incrementing
                        keys, so you should specify the name of a sequence to
                         <span class="methodname">lastInsertId()</span> or
                         <span class="methodname">lastSequenceId()</span>.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">
                        Currently the <b><tt>Zend_Db::CASE_FOLDING</tt></b> option
                        is not supported by the Firebird (Interbase) adapter.
                        Unquoted identifiers are automatically returned in
                        upper case.
                    </p>
                </li>

                <li class="listitem">
                    <p class="para">Adapter name is <span class="classname">ZendX_Db_Adapter_Firebird</span>.</p>

                    <p class="para">
                        Remember to use the param adapterNamespace with value
                        <span class="classname">ZendX_Db_Adapter</span>.
                    </p>

                    <p class="para">
                        We recommend to update the <var class="filename">gds32.dll</var> (or linux
                        equivalent) bundled with <acronym class="acronym">PHP</acronym>, to the same version of the
                        server. For Firebird the equivalent <var class="filename">gds32.dll</var> is
                        <var class="filename">fbclient.dll</var>.
                    </p>

                    <p class="para">
                        By default all identifiers (tables names, fields) are returned in upper
                        case.
                    </p>
                </li>
            </ul>
        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.db.html">Zend_Db</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.db.html">Zend_Db</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.db.statement.html">Zend_Db_Statement</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.db.html">Zend_Db</a></li>
  <li class="active"><a href="zend.db.adapter.html">Zend_Db_Adapter</a></li>
  <li><a href="zend.db.statement.html">Zend_Db_Statement</a></li>
  <li><a href="zend.db.profiler.html">Zend_Db_Profiler</a></li>
  <li><a href="zend.db.select.html">Zend_Db_Select</a></li>
  <li><a href="zend.db.table.html">Zend_Db_Table</a></li>
  <li><a href="zend.db.table.row.html">Zend_Db_Table_Row</a></li>
  <li><a href="zend.db.table.rowset.html">Zend_Db_Table_Rowset</a></li>
  <li><a href="zend.db.table.relationships.html">Zend_Db_Table Relationships</a></li>
  <li><a href="zend.db.table.definition.html">Zend_Db_Table_Definition</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>